package de.preisrobot.entity;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.codec.binary.Base64;

@Entity
@Table(name="anbieterlinks")
public class CrawlerLinkUrl {

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	long id;
	
	private String linkhash;
	
	private String link;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="lastvisited")
	private Date lastvisited;

	private int anbieterId;
	private int brokenLink;
	
	private int linktyp;
	
	private int categoryId;
  
	public void setLink(String link) {
		this.link = link;
		
		MessageDigest md = null;
      try
      {
         md = MessageDigest.getInstance("MD5");
         Base64  base64 = new Base64 ();
         if(link != null)
         {
            byte[] digest = md.digest(link.getBytes());
            linkhash = new String(base64.encode(digest));
         }
      }
      catch (NoSuchAlgorithmException e)
      {
         e.printStackTrace();
      }
    
	}

	public String getLink() {
		return link;
	}

	public void setLastvisited(Date lastvisited) {
		this.lastvisited = lastvisited;
	}

	public Date getLastvisited() {
		return lastvisited;
	}

	public void setAnbieterId(int anbieterId) {
		this.anbieterId = anbieterId;
	}

	public int getAnbieterId() {
		return anbieterId;
	}

	public void setBrokenLink(int brokenLink) {
		this.brokenLink = brokenLink;
	}

	public int getBrokenLink() {
		return brokenLink;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

   public void setLinktyp(int linktyp)
   {
      this.linktyp = linktyp;
   }

   public int getLinktyp()
   {
      return linktyp;
   }

   public void setLinkhash(String linkhash)
   {
      this.linkhash = linkhash;
   }

   public String getLinkhash()
   {
      return linkhash;
   }

   public void setCategoryId(int categoryId)
   {
      this.categoryId = categoryId;
   }

   public int getCategoryId()
   {
      return categoryId;
   }

@Override
public String toString() {
	return "CrawlerLinkUrl [id=" + id + ", link=" + link + ", anbieterId="
			+ anbieterId + ", categoryId=" + categoryId + "]";
}

}
